<?php
namespace Home\Controller;
use Datacore\Service\CategoryService;
use Datacore\Service\UserService;
use Datacore\Utils\DataGridView;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        echo "thinkphp结合ORM编程实列";
    }
    
    public function userList()
    {
        $where = " id <> 0";
        $list = UserService::getUserlist($where);
        DataGridView::listView($list,10,"");
    }
    
    public function userAdd()
    {
        $parms = I('post.');
        try{
            $res = UserService::addUser($parms);
            if(!$res)DataGridView::errorView('400','添加失败');
            DataGridView::successsView('添加成功');
        }catch (\Exception $e){
            DataGridView::errorView(500,$e->getMessage());
        }
    }
    
    public function userUpdate()
    {
        $parms = I('post.');
        try{
            $res = UserService::updateUser($parms);
            if(!$res)DataGridView::errorView('400','编辑失败');
            DataGridView::successsView('编辑成功');
        }catch (\Exception $e){
            DataGridView::errorView(500,$e->getMessage());
        }
    }
    
    public function testPage()
    {
        $parms = I('get.');
        $where = 'show_status=1';
        $data = CategoryService::getCategoryList($where,$parms );
        $this->assign('list',$data['list']);
        $this->assign('page',$data['Page']);
        $this->display();
    }
}